using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfValidatorDemo.Converters
{
    public class MessageColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string message)
            {
                if (string.IsNullOrEmpty(message))
                    return Brushes.Black;

                if (message.Contains("成功"))
                    return Brushes.Green;
                else if (message.Contains("失败") || message.Contains("错误"))
                    return Brushes.Red;
            }

            return Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}